package pe.edu.pucp.notasmoviles.jms;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

@Component
public class QueueSender {
	
	private JmsTemplate jmsTemplate;
	
	@Autowired
	public QueueSender(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
	
	public String send(String message){
		jmsTemplate.setPubSubDomain(true); // Para enviar a un topic
		jmsTemplate.convertAndSend("topic_request", message);
		jmsTemplate.setPubSubDomain(false); // Para enviar a un queue
		return jmsTemplate.receiveAndConvert("cola_response").toString();
	}
}
